package com.wanchuang.shengfubao.module.mine;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.protobuf.InvalidProtocolBufferException;
import com.wanchuang.shengfubao.R;
import com.wanchuang.shengfubao.base.BaseActivity;
import com.wanchuang.shengfubao.help.GlideHelper;
import com.wanchuang.shengfubao.net.Apis;
import com.wanchuang.shengfubao.net.NetworkManager;
import com.wanchuang.shengfubao.net.interfaces.OnRequestCallBack;
import com.wanchuang.shengfubao.proto.Memberinviter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class QrActivity extends BaseActivity {

    @BindView(R.id.tv_name)
    TextView tv_name;

    @BindView(R.id.tv_title)
    TextView tv_title;

    @BindView(R.id.iv_head)
    ImageView iv_head;

    @BindView(R.id.iv_qr)
    ImageView iv_qr;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qr);
        ButterKnife.bind(this);
        tv_title.setText("我的邀请码");
        submit();
    }

    @OnClick({R.id.back_iv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_iv:
                finish();
                break;
        }
    }

    private void submit() {
        NetworkManager.INSTANCE.post(Apis.get_my_qrcode_inviter, new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) throws InvalidProtocolBufferException {
                Memberinviter.get_my_qrcode_inviter data = Memberinviter.get_my_qrcode_inviter.parseFrom(response);
                tv_name.setText(data.getMemberName());
                GlideHelper.INSTANCE.loadAvatar(iv_head, data.getMemberAvatar());
                GlideHelper.INSTANCE.loadImage(iv_qr, data.getQrcodeUrl());

            }

            @Override
            public void onError(int code, String errorMessage) {
                showToast(errorMessage);
                hideProgress();
                if (code == 200) {
                    finish();
                }
            }
        });

    }
}
